package cn.com.workflow.util;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public abstract class JsonUtils {
	public static String ToJson(Object obj){
		ObjectMapper mapper = new ObjectMapper();
		try {
			return mapper.writeValueAsString(obj);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
			return "transJson error";
		}
	}
	
	public static Object ParseJson(String json, Class<?> c){
		ObjectMapper mapper = new ObjectMapper();
		try {
			return mapper.readValue(json, c);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static Map<String, String> ParseJsonToMap(String json){
		try {
			   return new ObjectMapper().readValue(json, HashMap.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new HashMap<String, String>();
	}
}
